from utility import *
from file_setting import *
import json, os



if __name__ == "__main__":
    # create data_set folder
    if not os.path.exists(DATA_SET_FOLDER):
        os.system("mkdir "+DATA_SET_FOLDER)



    data_set_generator = DataSetGenerator()
    # create server setting
    SERVER_NUMBER = 10
    server_data_set = data_set_generator.generate_server_data_set(
        create_sample_server(), SERVER_NUMBER)
    with open(SERVER_DATA_SET_FILE_NAME, "w") as f:
        json.dump(server_data_set, f)



    # create server capacity tasks
    TASK_NUMBER = 1000
    server_capacity_task_data_set = data_set_generator.generate_server_capacity_task_data_set(
        create_sample_server(), TASK_NUMBER)
    with open(SERVER_CAPACITY_TASKS_DATA_SET_FILE_NAME, "w") as f:
        json.dump(server_capacity_task_data_set, f)



    # create uniform distribution tasks
    UNIFORM_DISTRIBUTION_PARAMETERS = {
        "cpu_lower_bound":      .1,
        "cpu_upper_bound":      .5,
        "memory_lower_bound":   .1,
        "memory_upper_bound":   .5,
        "blkio_lower_bound":    1,
        "blkio_upper_bound":    5,
        "network_lower_bound":  .1,
        "network_upper_bound":  .5,
    }
    uniform_distribution_task_data_set = data_set_generator.generate_uniform_distribution_task_data_set(
        UNIFORM_DISTRIBUTION_PARAMETERS, TASK_NUMBER)
    with open(UNIFORM_DISTRIBUTION_TASKS_DATA_SET_FILE_NAME, "w") as f:
        json.dump(uniform_distribution_task_data_set, f)



    # create normal distribution tasks
    NORMAL_DISTRIBUTION_PARAMETERS = {
        "cpu_average":          .1,
        "cpu_variance":         .025,
        "memory_average":       .2,
        "memory_variance":      .05,
        "blkio_average":        2,
        "blkio_variance":       .5,
        "network_average":      .1,
        "network_variance":     .025,
    }
    normal_distribution_task_data_set = data_set_generator.generate_normal_distribution_task_data_set(
        NORMAL_DISTRIBUTION_PARAMETERS, TASK_NUMBER)
    with open(NORMAL_DISTRIBUTION_TASKS_DATA_SET_FILE_NAME, "w") as f:
        json.dump(normal_distribution_task_data_set, f)



    alpha = 5
    beta = 8
    # create cpu intensive tasks
    CPU_INTENSIVE_TASKS_PARAMETERS = {
        "cpu_average":          .1,
        "cpu_variance":         .025,
        "memory_average":       .2 / beta,
        "memory_variance":      .05 / beta,
        "blkio_average":        2 / beta,
        "blkio_variance":       .5 / beta,
        "network_average":      .1 / beta,
        "network_variance":     .025 / beta,
    }
    for key in CPU_INTENSIVE_TASKS_PARAMETERS:
        CPU_INTENSIVE_TASKS_PARAMETERS[key] *= alpha
    cpu_intensive_tasks_data_set = data_set_generator.generate_normal_distribution_task_data_set(
        CPU_INTENSIVE_TASKS_PARAMETERS, TASK_NUMBER)
    with open(CPU_INTENSIVE_TASKS_DATA_SET_FILE_NAME, "w") as f:
        json.dump(cpu_intensive_tasks_data_set, f)



    # create io intensive tasks
    IO_INTENSIVE_TASKS_PARAMETERS = {
        "cpu_average":          .1 / beta,
        "cpu_variance":         .025 / beta,
        "memory_average":       .2,
        "memory_variance":      .05,
        "blkio_average":        2,
        "blkio_variance":       .5,
        "network_average":      .1 / beta,
        "network_variance":     .025 / beta,   
    }
    for key in IO_INTENSIVE_TASKS_PARAMETERS:
        IO_INTENSIVE_TASKS_PARAMETERS[key] *= alpha
    io_intensive_tasks_data_set = data_set_generator.generate_normal_distribution_task_data_set(
        IO_INTENSIVE_TASKS_PARAMETERS, TASK_NUMBER)
    with open(IO_INTENSIVE_TASKS_DATA_SET_FILE_NAME, "w") as f:
        json.dump(io_intensive_tasks_data_set, f)



    # create network intensive tasks
    NETWORK_INTENSIVE_TASKS_PARAMETERS = {
        "cpu_average":          .1 / beta,
        "cpu_variance":         .025 / beta,
        "memory_average":       .2 / beta,
        "memory_variance":      .05 / beta,
        "blkio_average":        2 / beta,
        "blkio_variance":       .5 / beta,
        "network_average":      .1,
        "network_variance":     .025,  
    }
    for key in NETWORK_INTENSIVE_TASKS_PARAMETERS:
        NETWORK_INTENSIVE_TASKS_PARAMETERS[key] *= alpha
    network_intensive_tasks_data_set = data_set_generator.generate_normal_distribution_task_data_set(
        NETWORK_INTENSIVE_TASKS_PARAMETERS, TASK_NUMBER)
    with open(NETWORK_INTENSIVE_TASKS_DATA_SET_FILE_NAME, "w") as f:
        json.dump(network_intensive_tasks_data_set, f)